﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThanhTu.GNC.Media.KQXS.DataAccess.BL;
using ThanhTu.GNC.Media.KQXS.DataAccess.DO;

namespace GNCMedia.KQXS.Admin
{
    public partial class AddnewTintuc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lbtnLogout_Click1(object sender, EventArgs e)
        {
            Session.Remove("UserName");
            Response.Redirect("Login.aspx");

        }

        protected void btn_addNewData_Click1(object sender, EventArgs e)
        {
            try
            {
                BreakingNewsBL brnew = new BreakingNewsBL();
                BreakingNewsDO BrnewDO = new BreakingNewsDO();
                if (!txt_content.Text.Trim().Equals(""))
                {
                    file_upload.SaveAs(Server.MapPath("images") + "//" + file_upload.FileName);
                    BrnewDO.Image = "../Admin/images/" + file_upload.FileName.ToString();
                    BrnewDO.Content = txt_content.Text.Trim();
                    BrnewDO.Groupnews = drl_muctin.SelectedIndex;
                   int checkInsert= brnew.SaveNews(BrnewDO);
                   if (checkInsert > 0)
                   {
                       lBLtHONGBAO.ForeColor = System.Drawing.Color.Blue;
                       lBLtHONGBAO.Text = "Thêm mới thành công";
                       Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('thêm mới Thành công);", true);
                   }
                   else
                   {
                       lBLtHONGBAO.ForeColor = System.Drawing.Color.Red;
                       lBLtHONGBAO.Text = "Thêm mới thành công";
                       Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('LỖI,XIN VUI LÒNG THỬ LẠI);", true);
                   }
                }
                else
                {
                    lBLtHONGBAO.Text = "Nội dung không được trống";
                }

            }
            catch (Exception ex)
            {
                Response.Write("lỗi thêm mới tin tức admin:" + ex);
            }
            finally
            {

            }
        }
    }
}